<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>

<div>
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'" onclick="openDialog()">添加</a>
    <a  href="javascript:void(0)" class="easyui-linkbutton"
        data-options="iconCls:'icon-remove'" onclick="DeleteGuru()">批量删除</a>
</div>
<table id="gurus"></table>
<div id="addGurus">
    <form id="addGuru" style="margin:30px" enctype="multipart/form-data" method="post">
        <table>
            <tr>
                <td>上师名字：<input name="guruName"/></td>
            </tr>
            <tr>
                <td>上师图片地址：<input name="guruimg" type="file"/></td>
            </tr>
            <tr>
                <td>上师法号：<input name="guruNickname" /></td>
            </tr>
        </table>
        <center>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="addGuru()">确认</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
        </center>
    </form>
</div>

<div id="updateGuru">
    <form id="myFormGuru"enctype="multipart/form-data" method="post">
        <table>
            <tr>
                <input id="gid" type="hidden" name="guruId"/>
                <td>上师名字：<input id="gname" name="guruName"/></td>
            </tr>
            <tr>
                <td>上师头像地址：<input name="gpic" type="file"/>
                </td>
                <td colspan="2"><p id="gImage"></p></td>
            </tr>
            <tr>
                <td>上师法号：<input id="gNname" name="guruNickname"/></td>
            </tr>
            <tr>
                <td>上师状态：<input id="gGurustatus" name="guruStatus"/></td>
            </tr>
        </table>
        <center>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onClick="updateGuru()">确认</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
        </center>
    </form>
</div>
<a href="#" onclick="down()">点击下载表中的数据下载</a>
<script type="text/javascript">
    function down(){
        $.ajax({
            url:"${pageContext.request.contextPath}/cmfzGuru/downLoad"
        })
    }

    $(function(){
        $("#addGurus").dialog({
            width:600,
            height:450,
            title:"添加轮播图",
            closed:true
        });
        $("#updateGuru").dialog({
            width:600,
            height:450,
            title:"修改",
            closed:true,
        });

            $('#gurus').datagrid({
                onDblClickRow: function(rowIndex,rowData){
                    $("#updateGuru").dialog("open");
                    $("#gid").val(rowData.guruId);
                    $("#gname").val(rowData.guruName);
                    $("#gImage").html("<img src='${pageContext.request.contextPath}" + rowData.guruImage + "' width=30px height=50px />");
                    $("#gNname").val(rowData.guruNickname);
                    $("#gGurustatus").val(rowData.guruStatus);
                },

                url:'${pageContext.request.contextPath}/cmfzGuru/queryAllCmfzGuru',
                pagination : true,
                pageList : [ 5, 10, 15, 20 ],
                pageSize : 5,
                javaType:"JSON",
                columns:[[
                    {checkbox:true},
                    {field:'guruId',title:'上师id',width:100},
                    {field:'guruName',title:'上师名字',width:100},
                    {field:'guruImage',title:'上师头像',width:100,align:'right',formatter: function (value, row, index) {
                        return "<img height='50' width='30' src='${pageContext.request.contextPath}"+value+"'/>";
                    }},
                    {field:'guruNickname',title:'上师昵称',width:100},
                    {field:'guruStatus',title:'上师状态',width:100},
                    {title : "操作",field : "cz",formatter : function(value, row, index) {
                            return "<a href='deleteBanner?ids=" + row.bannerId + "'>删除</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='update()'>修改</a>";
                        }
                    }
                ]]
            });
        }
    )

//    删除
    function DeleteGuru(){
        var idd = $("#gurus").datagrid("getSelections");
        if(idd.length==0){
            //提示框
            $.messager.alert('提示框',"请选择要删除的信息",'warning');
        }else{
            //提示框
            $.messager.confirm('提示框',"确定要删除吗",function(d){
                if(d){
                    //存储所有的id
                    var id = new Array();
                    for(var i=0;i<idd.length;i++){
                        id[i]=idd[i].guruId;
                    }
                    //alert(id);
                    $.ajax({
                        url:"${pageContext.request.contextPath}/cmfzGuru/deleteCmfzGuru",
                        type:"post",
                        data:"ids="+id,
                        success:function(data){
                            if(data){
                                $.messager.alert('提示框',"删除成功",'info');
                                $("#gurus").datagrid("reload");
                            }else{
                                $.messager.alert('提示框',"删除失败",'warning');
                            }
                        }
                    });
                }
            });
        }
    }
    function openDialog(){
        $("#addGurus").dialog("open");
    }
    //添加
    function addGuru(){
        $('#addGuru').form('submit', {
            url:"${pageContext.request.contextPath}/cmfzGuru/insertCmfzGuru",
            onSubmit: function(){
                return true;
            },
            success:function(data){
                if(addGuru){
                    $.messager.alert('提示框',"添加成功",'info');
                    $("#gurus").datagrid("reload");
                    $("#addGurus").dialog("close");
                }else{
                    $.messager.alert('提示框',"添加失败",'warning');
                }

            }
        });
    }
    function updateGuru(){
        $("#myFormGuru").form("submit",{
            url:"${pageContext.request.contextPath}/cmfzGuru/updateCmfzGuru",
            success:function(data){
                if(data){
                    $.messager.alert('提示框',"修改成功",'info');
                    $("#gurus").datagrid("reload");
                    $("#updateGuru").dialog("close");
                }else{
                    $.messager.alert("提示框","修改失败","warning");
                }
            }
        });
    }
</script>